/**
 * 简单的SERVICE类
 * 如果SERVICE中只需要进行简单的增删改查操作，就可以调用这个SERVICE类来操作
 * 此SERVICE类针对HIBERNATE编写
 */
package cn.antia.cep.busi;

import java.util.*;

import cn.antia.cep.common.*;
import cn.antia.cep.db.DBException;
import cn.antia.cep.db.hibernate.dao.*;

/**
 * @author sunkeei
 */
public class DbHibernateService extends HibeGenericDAO{

    /**
     * 判断是否已经存在相似的记录
     *
     * @param o Object
     * @return boolean
     * @throws BusiException e
     */
    public boolean isExistEntity(Object o) throws BusiException {
        try {
            List list = find(o, true);
            return !(list == null || list.size() < 1);
        } catch (DBException dbe) {
            BusiException be = new BusiException("001",dbe.toString());
            SysExceptionTool.addExceptionInfo(be);
            throw be;
        }
    }

    /**
     * 查询第一条记录
     *
     * @param hql hql
     * @return Object
     * @throws BusiException e
     */
    public Object findFirstRecordService(String hql) throws BusiException {
        try {
            List list = find(hql);
            if (list == null || list.size() < 1) {
                return null;
            }
            return list.get(0);
        }catch(DBException dbe){
            BusiException be = new BusiException("001",dbe.toString());
            SysExceptionTool.addExceptionInfo(be);
            throw be;
        }
	}
}
